package de.hhn.mim.psb;

import java.util.ArrayList;

import org.junit.Test;

public class TREFRETest {

	@Test
	public void treTest(){
		 System.out.println("beisp3_TREmitPolarisDaten\n");
		    
		    System.out.println("Sie muessen die LMRegist.calcTrafos implementieren, \n" +
		                       "sonst wird nur eine dummy-Implemtierung verwendet, " +
		                       "die falsche Ergebnisse liefert!");
		    
		    Vect3D fixed0  = new Vect3D(255.0610, 272.1390, 202.870); 
		    Vect3D fixed1  = new Vect3D(208.9190, 312.8810, 87.1480);
		    Vect3D fixed2  = new Vect3D(309.0100, 357.0810, 93.7060);
		    Vect3D float0  = new Vect3D(-178.880, -64.770, 1659.270);
		    Vect3D float1  = new Vect3D(-65.590, -95.910, 1712.930);
		    Vect3D float2  = new Vect3D(-92.740, -5.130, 1760.030);
		    /* Ausgabe in MITK FRE is 1.777 mm (Std.Dev. 0.480
		     * min. Registration error (best fitting landmark) is 1.319 mm
		     * max. Registration error (worst fitting landmark) is 2.275 mm
		     */
		    LMRegist.LMPair [] lms = new LMRegist.LMPair[3];
		    lms[0] = new LMRegist.LMPair(fixed0, float0);
		    lms[1] = new LMRegist.LMPair(fixed1, float1);
		    lms[2] = new LMRegist.LMPair(fixed2, float2);
		    
		    ArrayList<Matrix3D> trafos = LMRegist.calcTrafos(lms);
		    
		    double   minFRE      = Double.MAX_VALUE;
		    
		    Matrix3D minFRETrafo = new Matrix3D(0);
		    for(int i = 0; i < trafos.size(); i++)
		     {
		      System.out.println("FRE Trafo[" + i + "]:");
		      double fre = LMRegist.calcFRE(lms, trafos.get(i));
		      if(fre < minFRE) 
		       {
		        minFRE = fre;
		        minFRETrafo = trafos.get(i);        
		       }
		     }
		     
		    System.out.printf("MinFRE: %7.2f\n", minFRE);
		    minFRETrafo.print("minFRETrafo");
		    int print = 2;
		    Vect3D [] points = new Vect3D[3];
		    points[0] = float0;
		    points[1] = float1;
		    points[2] = float2;
		    System.out.printf("Punkte\n");
		    for(int i = 0; i < points.length; i++)
		     {
		      points[i].print("P[" + i + "]");
		     }
		    Vect3D target = Vect3D.mean(points);
		    target.print("Angenommener TP (Schwerpunkt)");
		    double tre = LMRegist.calcTRE(target, minFRE, points, minFRETrafo);
		    System.out.printf("TRE:  %7.2f \n", tre);

		    // TRE                    fuer Trafo     fuer Trafo
		    //                       mit FRE 2.34   mit FRE 1.83 (kleinster FRE)
		    // TRE fuer Zentrum (mean): 2.34,           1,83
		    // TRE fuer p[0]:           3.03            2.36
		    // TRE fuer [0,0,0]:      26,996           21.04  
		    System.out.println("\n\n\n");
	}
}
